package com.mmf.ancientcostume.adapter.goods;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.mmf.ancientcostume.R;
import com.mmf.ancientcostume.base.adapter.MyBaseRecyclerAdapter;
import com.mmf.ancientcostume.common.utils.DipUtil;
import com.mmf.ancientcostume.common.utils.service.SecretConstant;
import com.mmf.ancientcostume.model.GoodsDetail;
import com.mmf.ancientcostume.widget.RecyclerTransformation;
import com.squareup.picasso.Picasso;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by MMF
 * date 2017/11/06
 * Description:收藏适配器
 */
public class CollectListAdapter extends MyBaseRecyclerAdapter<CollectListAdapter.ViewHolder, GoodsDetail> {
    Picasso picasso;
    private int width;


    public CollectListAdapter(Context context) {
        super(context);
        this.context = context;
        picasso = Picasso.with(context);
        width = (DipUtil.getWidth(context) - DipUtil.dip2px(context, 8)) / 2;
    }
    @Override
    protected int getLayout() {
        return R.layout.adapter_goods_list ;
    }

    @Override
    protected ViewHolder getViewHolder(View beanView) {
        ViewHolder mHolder = new ViewHolder(beanView);
        return mHolder;
    }

    @Override
    protected void setValues(ViewHolder holder, GoodsDetail bean) {
        ViewHolder viewHolder = (ViewHolder) holder;
        //设置图片显示的宽高
        ViewGroup.MarginLayoutParams margin9 = new ViewGroup.MarginLayoutParams(
                viewHolder.ivHome.getLayoutParams());
        LinearLayout.LayoutParams layoutParams9 = new LinearLayout.LayoutParams(margin9);
        layoutParams9.height = LinearLayout.LayoutParams.WRAP_CONTENT;//设置图片的高度
        layoutParams9.width = width; //设置图片的宽度
        viewHolder.ivHome.setLayoutParams(layoutParams9);
        picasso.load(SecretConstant.API_HOST + "/upload/" + bean.getImgName())
                .noFade()
                .placeholder(R.drawable.pictures_no)
                .error(R.drawable.pictures_no)
                .transform(new RecyclerTransformation(width))
                .into(viewHolder.ivHome);
        viewHolder.tvTittle.setText(bean.getDescribe());
        viewHolder.tvRental.setText("租金：" + bean.getRental());
        viewHolder.tvDeposit.setText("押金：" + bean.getDeposit());
    }

    static class ViewHolder extends RecyclerView.ViewHolder {
        @BindView(R.id.iv_home)
        ImageView ivHome;
        @BindView(R.id.tv_tittle)
        TextView tvTittle;
        @BindView(R.id.tv_rental)
        TextView tvRental;
        @BindView(R.id.tv_deposit)
        TextView tvDeposit;
        @BindView(R.id.lyt_goods_list)
        LinearLayout lytGoodsList;

        ViewHolder(View view) {
            super(view);
            ButterKnife.bind(this, view);
        }
    }

}
